/**
 * tabpanel封装
 */
(function($ns){
    
    $ns.instance = null;

    /**
     * 初始化
     */
    $ns.init = function() {
        this.instance = new TabPanel({
            renderTo: 'tab',
            height: document.documentElement.clientHeight - 70,
            width: document.documentElement.clientWidth - 231,
            border: 'none',
            active: 0,
            items: [
				{
				    id: 'toolbarPlugin',
				    title: '起始页',
				    html: '<iframe id="toolbarPluginFrame" src="'+ QG_CONFIG.PATH +'default.jsp" width="100%" height="100%" frameborder="0"></iframe>'
				}
            ],
            maxLength: 10
        });
        
        return this.instance;
    }
    
    /**
     * 显示首页
     */
    $ns.showInitPage = function() {
		this.addTab({
		    id: 'toolbarPlugin',
		    title: '起始页',
		    html: '<iframe id="toolbarPluginFrame" src="'+ QG_CONFIG.PATH +'default.jsp" width="100%" height="100%" frameborder="0"></iframe>'
		});
    }
    
    /**
     * 获取panel实例
     */
    $ns.getInstance = function() {
        return this.instance;
    }
    
    /**
     * 添加tab
     * @param config
     */
    $ns.addTab = function(config) {
        this.getInstance().addTab(config);
    }
    
    /**
     * 移除tab
     * @param tabId
     */
    $ns.removeTab = function(tabId) {
        var panel = this.getInstance();
        // 移除标签
        panel.kill(tabId);
        // 激活最后一个标签
        var count = panel.getTabsCount();
        if(count > 0) panel.show(count-1, -1);
    }
    
    /**
     * 重新设置tab的大小
     */
    $ns.resize = function() {
        var panel = this.getInstance();
        panel.resize();
    }
    
    /**
     * 改变tab title
     * @param tabId
     * @param title
     */
    $ns.changeTabTitle = function(tabId, title) {
        title = title || "";
        this.getInstance().setTitle(tabId, title);
    }
    
})(using("Qadmin.App.Panel"));